﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:SYS_SENSINFO
	/// </summary>
	public partial class SYS_SENSINFO : BaseDAL<GSLMS.Entity.TB_SYS_SENSINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public SYS_SENSINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_SYS_SENSINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_INFOTYPE", model.INFOTYPE),
								new OracleParameter("P_NAME", model.NAME),
								new OracleParameter("P_IDCARD", model.IDCARD),
								new OracleParameter("P_CARDADDR", model.CARDADDR),
								new OracleParameter("P_HOMEADDR", model.HOMEADDR),
								new OracleParameter("P_SEX", model.SEX),
								new OracleParameter("P_POST", model.POST),
								new OracleParameter("P_POSTADDR", model.POSTADDR),
								new OracleParameter("P_MOBILE", model.MOBILE),
								new OracleParameter("P_HOMETELCODE", model.HOMETELCODE),
								new OracleParameter("P_HOMETEL", model.HOMETEL),
								new OracleParameter("P_POSTTELCODE", model.POSTTELCODE),
								new OracleParameter("P_POSTTEL", model.POSTTEL),
								new OracleParameter("P_JOBUNIT", model.JOBUNIT),
								new OracleParameter("P_JOBTELCODE", model.JOBTELCODE),
								new OracleParameter("P_JOBTEL", model.JOBTEL),
								new OracleParameter("P_JOBTELSUB", model.JOBTELSUB),
								new OracleParameter("P_SPOUSENAME", model.SPOUSENAME),
								new OracleParameter("P_SPOUSEMOBILE", model.SPOUSEMOBILE),
								new OracleParameter("P_SPOUSETELCODE", model.SPOUSETELCODE),
								new OracleParameter("P_SPOUSETEL", model.SPOUSETEL),
								new OracleParameter("P_CREATETIME", model.CREATETIME),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_MODIFYTIME", model.MODIFYTIME),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 27; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_sys.proc_sensinfo_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_SYS_SENSINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_INFOTYPE", model.INFOTYPE),
								new OracleParameter("P_NAME", model.NAME),
								new OracleParameter("P_IDCARD", model.IDCARD),
								new OracleParameter("P_CARDADDR", model.CARDADDR),
								new OracleParameter("P_HOMEADDR", model.HOMEADDR),
								new OracleParameter("P_SEX", model.SEX),
								new OracleParameter("P_POST", model.POST),
								new OracleParameter("P_POSTADDR", model.POSTADDR),
								new OracleParameter("P_MOBILE", model.MOBILE),
								new OracleParameter("P_HOMETELCODE", model.HOMETELCODE),
								new OracleParameter("P_HOMETEL", model.HOMETEL),
								new OracleParameter("P_POSTTELCODE", model.POSTTELCODE),
								new OracleParameter("P_POSTTEL", model.POSTTEL),
								new OracleParameter("P_JOBUNIT", model.JOBUNIT),
								new OracleParameter("P_JOBTELCODE", model.JOBTELCODE),
								new OracleParameter("P_JOBTEL", model.JOBTEL),
								new OracleParameter("P_JOBTELSUB", model.JOBTELSUB),
								new OracleParameter("P_SPOUSENAME", model.SPOUSENAME),
								new OracleParameter("P_SPOUSEMOBILE", model.SPOUSEMOBILE),
								new OracleParameter("P_SPOUSETELCODE", model.SPOUSETELCODE),
								new OracleParameter("P_SPOUSETEL", model.SPOUSETEL),
								new OracleParameter("P_CREATETIME", model.CREATETIME),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_MODIFYTIME", model.MODIFYTIME),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 27; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_sys.proc_sensinfo_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_sys.proc_sensinfo_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_SYS_SENSINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_SYS_SENSINFO model = new GSLMS.Entity.TB_SYS_SENSINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["INFOTYPE"]!=null && dr["INFOTYPE"].ToString()!="")
				{
					model.INFOTYPE=dr["INFOTYPE"].ToString();
				}
				if(dr["NAME"]!=null && dr["NAME"].ToString()!="")
				{
					model.NAME=dr["NAME"].ToString();
				}
				if(dr["IDCARD"]!=null && dr["IDCARD"].ToString()!="")
				{
					model.IDCARD=dr["IDCARD"].ToString();
				}
				if(dr["CARDADDR"]!=null && dr["CARDADDR"].ToString()!="")
				{
					model.CARDADDR=dr["CARDADDR"].ToString();
				}
				if(dr["HOMEADDR"]!=null && dr["HOMEADDR"].ToString()!="")
				{
					model.HOMEADDR=dr["HOMEADDR"].ToString();
				}
				if(dr["SEX"]!=null && dr["SEX"].ToString()!="")
				{
					model.SEX=dr["SEX"].ToString();
				}
				if(dr["POST"]!=null && dr["POST"].ToString()!="")
				{
					model.POST=dr["POST"].ToString();
				}
				if(dr["POSTADDR"]!=null && dr["POSTADDR"].ToString()!="")
				{
					model.POSTADDR=dr["POSTADDR"].ToString();
				}
				if(dr["MOBILE"]!=null && dr["MOBILE"].ToString()!="")
				{
					model.MOBILE=dr["MOBILE"].ToString();
				}
				if(dr["HOMETELCODE"]!=null && dr["HOMETELCODE"].ToString()!="")
				{
					model.HOMETELCODE=dr["HOMETELCODE"].ToString();
				}
				if(dr["HOMETEL"]!=null && dr["HOMETEL"].ToString()!="")
				{
					model.HOMETEL=dr["HOMETEL"].ToString();
				}
				if(dr["POSTTELCODE"]!=null && dr["POSTTELCODE"].ToString()!="")
				{
					model.POSTTELCODE=dr["POSTTELCODE"].ToString();
				}
				if(dr["POSTTEL"]!=null && dr["POSTTEL"].ToString()!="")
				{
					model.POSTTEL=dr["POSTTEL"].ToString();
				}
				if(dr["JOBUNIT"]!=null && dr["JOBUNIT"].ToString()!="")
				{
					model.JOBUNIT=dr["JOBUNIT"].ToString();
				}
				if(dr["JOBTELCODE"]!=null && dr["JOBTELCODE"].ToString()!="")
				{
					model.JOBTELCODE=dr["JOBTELCODE"].ToString();
				}
				if(dr["JOBTEL"]!=null && dr["JOBTEL"].ToString()!="")
				{
					model.JOBTEL=dr["JOBTEL"].ToString();
				}
				if(dr["JOBTELSUB"]!=null && dr["JOBTELSUB"].ToString()!="")
				{
					model.JOBTELSUB=dr["JOBTELSUB"].ToString();
				}
				if(dr["SPOUSENAME"]!=null && dr["SPOUSENAME"].ToString()!="")
				{
					model.SPOUSENAME=dr["SPOUSENAME"].ToString();
				}
				if(dr["SPOUSEMOBILE"]!=null && dr["SPOUSEMOBILE"].ToString()!="")
				{
					model.SPOUSEMOBILE=dr["SPOUSEMOBILE"].ToString();
				}
				if(dr["SPOUSETELCODE"]!=null && dr["SPOUSETELCODE"].ToString()!="")
				{
					model.SPOUSETELCODE=dr["SPOUSETELCODE"].ToString();
				}
				if(dr["SPOUSETEL"]!=null && dr["SPOUSETEL"].ToString()!="")
				{
					model.SPOUSETEL=dr["SPOUSETEL"].ToString();
				}
				if(dr["CREATETIME"]!=null && dr["CREATETIME"].ToString()!="")
				{
					model.CREATETIME=DateTime.Parse(dr["CREATETIME"].ToString());
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["MODIFYTIME"]!=null && dr["MODIFYTIME"].ToString()!="")
				{
					model.MODIFYTIME=DateTime.Parse(dr["MODIFYTIME"].ToString());
				}
				if(dr["MODIFYBY"]!=null && dr["MODIFYBY"].ToString()!="")
				{
					model.MODIFYBY=dr["MODIFYBY"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_SYS_SENSINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_SYS_SENSINFO sModel = new GSLMS.Entity.TB_SYS_SENSINFO();
			string sql = "";
			sql = "select * from TB_SYS_SENSINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_SYS_SENSINFO> GetList(GSLMS.Entity.TB_SYS_SENSINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_SYS_SENSINFO>();
			DataTable dt = null;
			string tblName = "TB_SYS_SENSINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_SYS_SENSINFO model = new GSLMS.Entity.TB_SYS_SENSINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

